﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Cormant.Mvc.Web
{
    [HtmlTag("td")]
    public class MvcTableCell : MvcControl
    {
        #region MvcTableCell : Constructors.
        public MvcTableCell(HtmlHelper html)
            : base(html, string.Empty)
        {
            this.Controls = new List<MvcHtmlTag>();
        }

        public MvcTableCell(HtmlHelper html, string id)
            : base(html, id)
        {
            this.Controls = new List<MvcHtmlTag>();
        }
        #endregion

        #region MvcTableCell : Properties.
        public IList<MvcHtmlTag> Controls { get; private set; }
        public string Text { get; set; }
        #endregion

        #region MvcTableCell : Methods.
        public override string ToString()
        {
            StringBuilder markup = new StringBuilder();
            // render the start tag...
            markup.AppendLine(base.ToString(TagRenderMode.StartTag));
            // render the inner html...
            if (this.Controls.Count == 0)
                markup.AppendLine(this.Text);
            else
            {
                foreach (MvcHtmlTag tag in this.Controls)
                    markup.AppendLine(tag.ToString());
            }
            // render the end tag...
            markup.AppendLine(base.ToString(TagRenderMode.EndTag));

            return markup.ToString();
        }
        #endregion
    }
}
